package com.edais.service.imp.gift;

import com.edais.domain.gift.PointFlow;
import com.edais.persistence.gift.PointFlowMapper;
import com.edais.service.gift.PointFlowService;
import com.edais.util.Consts;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * PointFlowServiceImpl
 * Created by haoyx on 2016/10/8.
 */
@Service
public class PointFlowServiceImpl implements PointFlowService {

    private static final Logger logger = Logger.getLogger(PointFlowServiceImpl.class);

    @Autowired
    private PointFlowMapper pointFlowMapper;

    @Override
    public void incomeFlow(String logInfo, PointFlow flow, Integer amount) {
        logger.info(logInfo+"创建积分收入流水");
        if(null == flow || null == amount){
            logger.info(logInfo+"创建积分收入流水失败flow-"+flow+"amount-"+amount);
            return;
        }
        this.createFlow(flow,amount, Consts.PointFlowType.INCOME);
        logger.info(logInfo+"创建积分收入流水成功");
    }

    @Override
    public void createFlow(PointFlow flow, Integer amount, String flowType) {
        if(null == flow || null == amount || StringUtils.isEmpty(flowType))
            return;
        flow.setFlowType(flowType);
        flow.setAmount(amount);
        flow.setCreatePer("javaservice");
        pointFlowMapper.insert(flow);
    }
}
